$(window).load(function() {

  var yuming = "https://h5.meetao.com",
    appid = "wx004631167cb38682",
    urlTwo = window.location.href,
    timestamp, noncestr, signature;

  $.ajax({
    type: "get",
    url: "https://oauth.meetao.com/api/uc/auth/getSignature/v2",
    data: {
      url: urlTwo
    },
    async: false,
    dataType: "json",
    jsonp: "callback",
    success: function(data) {
      var objData = data;
      timestamp = objData.timestamp;
      noncestr = objData.noncestr;
      signature = objData.signature;
      wxShare();
    },
    error: function(e) {
      console.log(e);
    }
  });

  function wxShare() {
    wx.config({
      debug: false,
      appId: appid,
      timestamp: timestamp,
      nonceStr: noncestr,
      signature: signature,
      jsApiList: [
        'onMenuShareAppMessage',
        'onMenuShareTimeline',
        "onMenuShareQQ",
        "onMenuShareQZone",
        "onMenuShareWeibo"
      ]
    });
  };

  function sharePopup() {
    $(".shareSuccess").show();
    $(".Mask").show();
    $(".safeguardExplain").hide();
    $(".van-modal").hide();
    $(".guide").hide();
  };

  wx.ready(function() {
    var stitle = '邀您参观姿美汇',
      sdesc = '分享健康生活 汇聚全球优品',
      shareImgUrl = 'https://h5.meetao.com/img/logo100.png', //姿美汇 MeetaoLive项目里的logo
      jumpUrl = urlTwo.split('/html/')[0] + '/html/index.html?shareUserId=' + shareUserId + '&shareShopCode=' + shareShopCode,
      isGiftInfo = !getQueryString('isGift') ? '' : '&isGift=' + getQueryString('isGift') + '&isGiftVip=' + getQueryString('isGiftVip');
    !!getQueryString('inviterId') && getQueryString('inviterId') != 'null' ? shareInfo.inviterId = getQueryString('inviterId') : shareInfo.inviterId = userId;

    if (urlTwo.indexOf('/html/productDetails.html?') > 0 && !getQueryString('isGiftGoods')) { //商品详情
      stitle = '姿美汇|' + $('.product-details-title span.product-shareTitle-info').attr('title');
      sdesc = '我在姿美汇发现了一个不错的商品，赶快来看看吧！';
      shareImgUrl = $('.product-swiper-box img').eq(0).attr('src');
      jumpUrl = urlTwo.split('/html/')[0] + '/html/productDetails.html?isFx=1&shareUserId=' + shareUserId + '&shareShopCode=' + shareShopCode + '&productId=' + getQueryString('productId') + isGiftInfo;
    } else if (urlTwo.indexOf('/html/rlStorer.html?') > 0) { //认领订单
      stitle = '免费领姿美汇VIP店主';
      sdesc = '双十一当天天猫成交满399元，免费领姿美汇VIP店主';
      jumpUrl = urlTwo.split('/html/')[0] + '/html/rlStorer.html';
    } else if ((urlTwo.indexOf('/html/productDetails.html?') > 0 && !!getQueryString('isGiftGoods')) || (urlTwo.indexOf('/html/indexOfGift.html?') > 0)) { //大礼包
      stitle = '姿美堂VIP店主';
      sdesc = '邀请您成为姿美汇VIP店主';
      jumpUrl = urlTwo.split('/html/')[0] + '/html/indexOfGift.html?shareUserId=' + shareUserId + '&shareShopCode=' + shareShopCode;
    } else if (urlTwo.indexOf('/html/PtPaySuccess.html') > 0 || urlTwo.indexOf('/html/PtShare.html') > 0 || urlTwo.indexOf('/html/PtDetails.html') > 0) { //拼团分享
      //拼团支付成功页 + 拼团商品详情页 - 分享
      stitle = '和我一起，立省' + fullPrice + '元拼' + goodsName;
      sdesc = '【仅剩' + isPtSuccess + '个名额，机会有限】' + sellingPointsDesc;
      shareImgUrl = imgUrl;
      jumpUrl = urlTwo.split('/html/')[0] + '/html/PtShare.html?virtualgoodsID=' + virtualgoodsID + '&activityId=' + activityId + '&groupId=' + groupId + '&GroupType=' + GroupType;
    } else if (urlTwo.indexOf('/html/PtIndex.html') > 0) { //拼团首页
      if (getQueryString('GroupType') == 'common_pt_groupon' || !getQueryString('GroupType')) {
        //普通拼团首页 - 分享
        stitle = '拼着买，更超值';
        sdesc = '优质产品，超低价格，快来姿美汇，等你马上开团';
        shareImgUrl = 'https://h5.meetao.com/img/PtShareLogo.png';
        jumpUrl = urlTwo.split('/html/')[0] + '/html/PtIndex.html?GroupType=common_pt_groupon';
      } else if (getQueryString('GroupType') == 'new_guest_pt_groupon') {
        //新人专享拼团首页 - 分享
        stitle = 'Hi，朋友！给你一个专属优惠';
        sdesc = '姿美汇新人专享拼团，优质产品，超值享受';
        shareImgUrl = 'https://h5.meetao.com/img/newPtShareLogo.png';
        jumpUrl = urlTwo.split('/html/')[0] + '/html/PtIndex.html?GroupType=new_guest_pt_groupon';
      };
    } else if (urlTwo.indexOf('/html/PtProductDetails.html') > 0) { //拼团商品详情 分享文案
      //拼团商品详情 - 分享
      stitle = '姿美汇|' + $('.product-details-title span').html();
      sdesc = '【有好货，共分享】快来和我一起参加姿美汇拼团吧！';
      shareImgUrl = $('.product-swiper-box img').eq(0).attr('src');
      jumpUrl = window.location.href;
    } else if (urlTwo.indexOf('/html/FPtVoteProducts.html') > 0 || urlTwo.indexOf('/html/FPtVoteGoodsDetails.html') > 0) { //票选优品 - 分享活动页 1
      stitle = '快来选你想要的';
      sdesc = '选你想要的，才是最好的，快来姿美汇参与票选优品，卖什么，你说了算！';
      shareImgUrl = 'http://pic.zimeitang.cn/group1/M00/80/E8/ecToXVwjbt2AShtHAAA9XLXFshM394.png';
      urlTwo.indexOf('/html/FPtVoteProducts.html') > 0 ? shareInfo.pageType = 'pageVoteActivityList' : shareInfo.pageType = 'pageMoreVoteActivityList';
      !shareInfo.activityIssueNum ? shareInfo.activityIssueNum = getQueryString('activityIssueNum') : '';
      jumpUrl = urlTwo.split('/html/')[0] + '/html/FPtVoteGoodsDetails.html?activityIssueNum=' + shareInfo.activityIssueNum;
      // jumpUrl = window.location.href;
    } else if (urlTwo.indexOf('/html/FPtVoteDetails.html') > 0) { //票选投票详情页 - 2
      stitle = '投票就能抽大奖，快来参与票选' + '\"' + $('.product_info-title').html() + '\"';
      sdesc = '选你想要的，才是最好的，快来姿美汇参与票选优品，投票后还能获得抽奖机会';
      shareImgUrl = $('.topImg img').eq(0).attr('src');
      shareInfo.title = stitle;
      shareInfo.imgUrl = shareImgUrl;
      shareInfo.address = window.location.href;
      shareInfo.pageType = 'pageVoteActivityItemDetail';
      setCookie('fxShareInfo', JSON.stringify(shareInfo));
      jumpUrl = window.location.href;
    } else if (urlTwo.indexOf('/html/FPtPayCall.html') > 0) { //票选支付成功回调页 - 3
      // 分享参数待确定
      // stitle = !!getCookie('fxShareInfo') ? JSON.parse(getCookie('fxShareInfo')).title : '快来姿美汇参与票选优品，投票后还能获得抽奖机会';
      // sdesc = '选你想要的，才是最好的，快来姿美汇参与票选优品，投票后还能获得抽奖机会';
      // shareImgUrl = JSON.parse(getCookie('fxShareInfo')).imgUrl;
      // jumpUrl = JSON.parse(getCookie('fxShareInfo')).address;
      stitle = '快来姿美汇参与票选优品，投票后还能获得抽奖机会';
      sdesc = '选你想要的，才是最好的，快来姿美汇参与票选优品，投票后还能获得抽奖机会';
      shareImgUrl = 'http://pic.zimeitang.cn/group1/M00/80/E8/ecToXVwjbt2AShtHAAA9XLXFshM394.png';
      jumpUrl = urlTwo.split('/html/')[0] + '/html/FPtVoteDetails.html?inviterId=' + shareInfo.inviterId + '&voteItemCode=' + getQueryString('voteItemCode');
      shareInfo.pageType = 'pageVoteActivityPaySuccess';
    } else if (urlTwo.indexOf('/html/FPtShareFriends.html') > 0 || urlTwo.indexOf('/html/FPtShareDetails.html') > 0) { //分享达人之旅 - 带期数的和不带期数的
      stitle = '快来抢占分享达人榜';
      // 增加达人榜是否上榜判断
      sdesc = shareInfo.info + '参与票选优品，变身分享达人！还能获取抽奖机会，奖品多多，惊喜不断！';
      shareImgUrl = 'http://pic.zimeitang.cn/group1/M00/CE/A9/ecToXVwklvuAF65hAAA0d7SeeuU143.png'; //分享图UI单出
      jumpUrl = urlTwo.split('/html/')[0] + '/html/FPtShareDetails.html?activityIssueNum=' + shareInfo.activityIssueNum;
      shareInfo.pageType = 'pageVoteActivityShareStar';
    } else if (urlTwo.indexOf('/html/FPtBackSource.html') > 0) { //溯源首页
      stitle = '优质好物，真实溯源';
      sdesc = '快来姿美汇，带你一起体验优质好物的真实探寻之旅';
      shareImgUrl = 'http://pic.zimeitang.cn/group1/M00/2F/59/ecToXVwly3WAFviqAACHaO-znIw517.png'; //分享图UI单出
      jumpUrl = window.location.href;
      shareInfo.pageType = 'pageVoteActivitySourceList';
    } else if (urlTwo.indexOf('/html/FPtSourceTalk.html') > 0 || urlTwo.indexOf('/html/FPtVoteVedioDetail.html') > 0) { //溯源详情
      stitle = shareInfo.stitle;
      // 增加达人榜是否上榜判断
      sdesc = '姿美汇又有新的优质好物探寻之旅，快来瞧瞧吧';
      shareImgUrl = shareInfo.imgUrl; //分享图UI单出
      jumpUrl = window.location.href;
      shareInfo.pageType = 'pageVoteActivitySourceDetail';
    } else if (urlTwo.indexOf('/html/FPtPrizeInit.html') > 0) { //抽奖分享文案
      stitle = '免费就能抽大奖，真实好礼送不停';
      sdesc = '红包、礼品、优惠券，多种奖品送不停，抽奖机会更能免费获取，快来姿美汇参与幸运大抽奖吧！';
      shareImgUrl = 'http://pic.zimeitang.cn/group1/M00/33/B7/cjf1-FwltBWAGV51AACizmhkI1g572.jpg'; //分享图UI单出
      jumpUrl = window.location.href;
    };
    if (jumpUrl.indexOf('shareUserId') < 0) {
      //分销商城 - 增加分享人ID or 上级ID
      jumpUrl.indexOf('.html?') < 0 ? jumpUrl = jumpUrl + "?shareUserId=" + shareUserId + ' &shareShopCode=' + shareShopCode + '&inviterId=' + shareInfo.inviterId : jumpUrl = jumpUrl + "&shareUserId=" + shareUserId + '&shareShopCode=' + shareShopCode + '&inviterId=' + shareInfo.inviterId;
    };
    wx.onMenuShareAppMessage({
      title: stitle,
      desc: sdesc,
      link: jumpUrl,
      imgUrl: shareImgUrl,
      success: function() {
        sharePopup(); //分享成功弹框显示
        saveShareLog('weixin'); //保存票选优品活动分享日志接口
      }
    });
    wx.onMenuShareTimeline({
      title: stitle,
      link: jumpUrl,
      imgUrl: shareImgUrl,
      success: function() {
        sharePopup(); //分享成功弹框显示
        saveShareLog('pengyouquan');
      }
    });
    wx.onMenuShareQQ({
      title: stitle,
      desc: sdesc,
      link: jumpUrl,
      imgUrl: shareImgUrl,
      success: function() {
        saveShareLog('qq');
      }
    });
    wx.onMenuShareQZone({
      title: stitle,
      desc: sdesc,
      link: jumpUrl,
      imgUrl: shareImgUrl,
      success: function() {
        saveShareLog('qq');
      }
    });
    wx.onMenuShareWeibo({
      title: stitle,
      desc: sdesc,
      link: jumpUrl,
      imgUrl: shareImgUrl,
      success: function() {
        saveShareLog('weibo');
      },
      cancel: function() {}
    });
  });
  /*进入姿美汇*/
  $("#on").on('click', function() {
    downAppFun();
  });
});
